<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="任务" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskId">
              <j-dict-select-tag type="list" v-model="model.taskId" dictCode="ins_task,task_no,id" placeholder="请选择任务" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="任务项" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="itemId">
              <j-dict-select-tag type="list" v-model="model.itemId" dictCode="ins_task_item,item_name,id" placeholder="请选择任务项" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="线路" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lineId">
              <j-dict-select-tag type="list" v-model="model.lineId" dictCode="ins_line,line_name,id" placeholder="请选择线路" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="巡检点位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pointId">
              <j-dict-select-tag type="list" v-model="model.pointId" dictCode="ins_point,point_name,id" placeholder="请选择巡检点位" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="巡检状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="insStatus">
              <j-dict-select-tag type="list" v-model="model.insStatus" dictCode="ins_status" placeholder="请选择巡检状态" />
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="12">
            <a-form-model-item label="巡检时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="insTime">
              <j-date placeholder="请选择巡检时间" v-model="model.insTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>-->
          <a-col :span="12">
            <a-form-model-item label="卡号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cardNo">
              <a-input v-model="model.cardNo" placeholder="请输入卡号"  ></a-input>
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="12">
            <a-form-model-item label="角色" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="roleId">
              <j-dict-select-tag type="list" v-model="model.roleId" dictCode="sys_role,role_name,id" placeholder="请选择角色" />
            </a-form-model-item>
          </a-col>-->
<!--          <a-col :span="12">-->
<!--            <a-form-model-item label="人员" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userId">-->
<!--              <j-select-user-by-dep v-model="model.userId" :multi="true" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="12">
            <a-form-model-item label="人员姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userName">
              <a-input v-model="model.userName" placeholder="请输入人员姓名"  ></a-input>
            </a-form-model-item>
          </a-col>-->
<!--          <a-col :span="12">
            <a-form-model-item label="部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deptId">
              <j-select-depart v-model="model.deptId" :multi="true"  />
            </a-form-model-item>
          </a-col>-->
          <a-col :span="12">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-input v-model="model.remark" placeholder="请输入备注"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'InsTaskRecordConnectForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
            insStatus:"1",
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          // taskId: [
          //   { required: true, message: '请选择任务!'},
          // ],
          // itemId: [
          //   { required: true, message: '请选择任务项!'},
          // ],
          lineId: [
            { required: true, message: '请选择线路!'},
          ],
         // userId: [
         //    { required: true, message: '请选择人员!'},
         // ],
         //  roleId: [
         //    { required: true, message: '请选择角色!'},
         //  ],
           insStatus: [
              { required: true, message: '请输入巡检状态!'},
           ],
           insTime: [
              { required: true, message: '请输入巡检时间!'},
           ],
          pointId: [
            { required: true, message: '请选择巡检点位!'},
          ],

        },
        url: {
          add: "/inspect/insTaskRecord/add",
          edit: "/inspect/insTaskRecord/edit",
          queryById: "/inspect/insTaskRecord/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>
